﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace ERPU8WebApi.Controllers
{
    public abstract class ApiControllerBase : ApiController
    {
        #region 响应方法
        [NonAction]
        public IHttpActionResult IHttpError(Models.ResponseCode resCode, string message)
        {
            Dictionary<string, object> dict = new Dictionary<string, object>();
            dict.Add("ResultCode", ((int)resCode).ToString());
            dict.Add("Message", message);
            return Json(dict);
        }

        [NonAction]
        public IHttpActionResult IHttpError(Models.ResponseCode resCode)
        {
            return IHttpError(resCode, Models.ResponseMsg.Msg(resCode));
        }

        [NonAction]
        public IHttpActionResult IHttpSuccess()
        {
            Models.ResponseCode resCode = Models.ResponseCode.OK;
            Dictionary<string, object> dict = new Dictionary<string, object>();
            dict.Add("ResultCode", ((int)resCode).ToString());
            dict.Add("Message", Models.ResponseMsg.Msg(resCode));
            return Json(dict);
        }

        [NonAction]
        public IHttpActionResult IHttpSuccess(object obj)
        {
            Models.ResponseCode resCode = Models.ResponseCode.OK;
            Dictionary<string, object> dict = new Dictionary<string, object>();
            dict.Add("ResultCode", ((int)resCode).ToString());
            dict.Add("Message", Models.ResponseMsg.Msg(resCode));
            dict.Add("DataList", obj);
            return Json(dict);
        }

        [NonAction]
        public IHttpActionResult IHttpSuccess(string message)
        {
            Models.ResponseCode resCode = Models.ResponseCode.OK;
            Dictionary<string, object> dict = new Dictionary<string, object>();
            dict.Add("ResultCode", ((int)resCode).ToString());
            dict.Add("Message", message);
            return Json(dict);
        }

        [NonAction]
        public IHttpActionResult IHttpResult(object obj)
        {
            return Json(obj);
        }


        #endregion
    }
}